from soj.builtin.compile.orchestrator import *
from soj.common.lang import *
from soj.builtin.execute.orchestrator import *

class AutorunOrchestrator:
    def __init__(self,exec:Path,lang:Language,
                 conf:Any|None=None):
        ensure_file(exec)
        self.lang=lang
        self.conf=conf
        self.exec:Path=exec

    def run(self,time:int,mem:int,input:Path,output:Path
            ,error:Path,report:Path)->ExecutionResult:
        ensure_file(input),ensure_file(output)
        ensure_file(error),ensure_file(report)
        # self.compile()
        if self.lang==Language.CPP:
            ro=ExecuteOrchestrator(self.exec,[],time,mem,input,output,error,report)
            ro.execute()
            return ro.get_result()
        elif self.lang==Language.PYTHON:
            ro=ExecuteOrchestrator("python",[self.exec],time,mem,input,output,error,report)
            ro.execute()
            return ro.get_result()
        else: raise NotImplementedError("Not supported language")
